import 'package:factoryside/api/api.dart';
import 'package:factoryside/bean/fee_order_entity.dart';
import 'package:factoryside/utils/request_util.dart';
import 'package:factoryside/utils/utils.dart';
import 'package:flutter/material.dart';

//审核费用单界面
class FeeAuditDetailPage extends StatefulWidget {
  FeeOrderEntity data;

  FeeAuditDetailPage(this.data);

  @override
  State<StatefulWidget> createState() {
    return _FeeAuditDetailState();
  }
}

class _FeeAuditDetailState extends State<FeeAuditDetailPage> {
  var checkRemarksCtr=TextEditingController();

  @override
  void dispose() {
    super.dispose();
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

  }
  ///通过拒绝
  bool _passSelected = false;
  bool _rejectSelected = false;

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
        appBar: AppBar(
          //导航栏
          title: Text(widget.data.feeNumber),
        ),
        body: widget.data!=null?Column(
          children: [
            Expanded(
              child: ListView(
                children: [
                  Container(
                    color: Colors.white,
                    child: Column(
                      children: [
                        buildContainer_base(),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Container(
              color: Colors.transparent,
              width: double.infinity,
              height: 50,
              margin: EdgeInsets.all(10),
              child: ElevatedButton(
                onPressed: () {
                  if(!_passSelected&&!_rejectSelected){
                    showToast('请选择是否通过！');
                    return;
                  }
                  if(_rejectSelected){
                    if(checkRemarksCtr.text.isEmpty){
                      showToast('请输入拒绝理由！');
                      return;
                    }
                  }
                  RequestUtil.post(
                      Api.auditOrderFee,{
                        'Id':widget.data.orderFeeApplicationID,
                    'State':_passSelected?8:-1,
                    'Remarks':checkRemarksCtr.text
                  }
                  ).then((value) => this.setState(() {
                    if(value['Data']['code']==0){
                      showToast('提交成功');
                      Navigator.pop(context,"提交成功");
                    }else{
                      showToast(value['Data']['msg']);
                    }
                  }));
                },
                child: Text(
                  '提交'
                )
              ),
            )
          ],
        ):Center(child: CircularProgressIndicator())
    );
  }

  ///基本信息
  Container buildContainer_base() {
    return Container(
        margin: EdgeInsets.symmetric(vertical: 10),
        padding: EdgeInsets.all(10),
        color: Colors.white,
        child: Column(
          children: [
            Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    // 复选框
                    GestureDetector(
                      child: Row(
                        children: [
                          Checkbox(
                              value: _passSelected,
                              onChanged: (value) {
                                setState(() {
                                  _passSelected = true;
                                  _rejectSelected = false;
                                });
                              }),
                          Text('通过',
                              textAlign: TextAlign.end,
                              style: TextStyle(
                                  fontSize: 16,
                                  color: Colors.black,
                                  fontWeight: FontWeight.bold)),
                        ],
                      ),
                      onTap: () {
                        setState(() {
                          _passSelected = true;
                          _rejectSelected = false;
                        });
                      },
                    ),
                    GestureDetector(
                      child: Row(
                        children: [
                          Checkbox(
                              value: _rejectSelected,
                              onChanged: (value) {
                                setState(() {
                                  _passSelected = false;
                                  _rejectSelected = true;
                                });
                              }),
                          Text('不通过',
                              textAlign: TextAlign.end,
                              style: TextStyle(
                                  fontSize: 16,
                                  color: Colors.black,
                                  fontWeight: FontWeight.bold)),
                        ],
                      ),
                      onTap: () {
                        setState(() {
                          _passSelected = false;
                          _rejectSelected = true;
                        });
                      },
                    ),
                  ],
                ),
              ],
            ),
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text('审核备注：',
                    textAlign: TextAlign.end,
                    style: TextStyle(
                        fontSize: 16,
                        color: Colors.black,
                        fontWeight: FontWeight.bold)),
                SizedBox(height: 10),
                TextField(
                  controller: checkRemarksCtr,
                  maxLines: 5,
                  decoration: InputDecoration(
                      hintText: '请输入审核备注',
                      contentPadding: EdgeInsets.all(10),
                      border: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(5.0),
                      )),
                ),
              ],
            ),
          ],
        ));
  }
}
